package com.example.demo.service;

import com.example.demo.entity.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class RedisRssServiceImpl implements RedisRssService {
    @Autowired
    private RedisMessageListenerContainer container;
    @Autowired
    private MessageListenerAdapter messageListenerAdapter;
    @Override
    public boolean isAllRss(Integer state) {
        return false;
    }

    @Override
    public boolean start(List<Channel> rediss) {
        for (Channel channel : rediss) {
            container.addMessageListener(messageListenerAdapter, new PatternTopic(channel.getChannel()));
        }
        return true;
    }

    @Override
    public boolean stop(List<Channel> rediss) {
        for (Channel channel : rediss) {
            container.removeMessageListener(messageListenerAdapter,new PatternTopic(channel.getChannel()));
        }
        return true;

    }

    @Override
    public List<Channel> allState() {
        return null;
    }

    @Override
    public List<Channel> state(List<Channel> rediss) {
        return null;
    }
}
